﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Portal.Cms.Model;
using System.Data;
using System.Collections.ObjectModel;
using DtSearchIndexService;
using Portal.Core;
using Portal.Web.Utility;

namespace Portal.Cms.Bussiness.Template
{
    public class CmsProcessTemplate : ICmsProcess
    {
        public virtual string ServiceId { get { return null; } }
        public virtual string ConnectionString(string SiteId) { return null; }

        public virtual void ChangePassword(
            string SiteId,
            string AssetCode,
            string LoginName,
            string OldPassword,
            string NewPassword,
            string ReNewPassword) { }
        public virtual DataTypeCls CreateDataTypeModel(string SiteId, string DataTypeId) { return null; }
        public virtual CmsDataCls CreateCmsDataModel(IDbTransaction Trans, string SiteId, string CmsDataId) { return null; }
        public virtual DataSaveHistoryCls CreateCmsDataHistoryModel(IDbTransaction Trans, string SiteId, string CmsDataId, string HistoryDataId) { return null; }
        public virtual CmsDataCls CreateCmsDataModel(IDbTransaction Trans, string SiteId, string CmsDataId, bool IncPreview, bool IncDownload) { return null; }
        public virtual CmsDataCls CreateCmsDataModel(IDbTransaction Trans, string SiteId, string CmsDataId, bool IncPreview, bool IncDownload, string ConnectionString) { return null; }

        public virtual GroupDataCls CreateGroupDataModel(IDbTransaction Trans, string SiteId, string GroupDataId) { return null; }
        public virtual DataTypeCls[] ReadingDataType(string SiteId) { return null; }
        public virtual DataTypeCls[] ReadingDataTypeForRelation(string SiteId) { return null; }
        public virtual GroupDataCls[] ReadingGroupData(string SiteId, string DataTypeId) { return null; }
        public virtual GroupDataCls[] ReadingGroupDataForPermission(string SiteId) { return null; }
        public virtual GroupDataCls[] ReadingGroupData(string SiteId, string DataTypeId, string AssetCode) { return null; }
        public virtual void AddGroupData(string SiteId, string DataTypeId, string Alias, string LinkDataAlias, string Subject, string Description) { }
        public virtual void SaveGroupData(string SiteId, string DataTypeId, string GroupDataId, string Alias, string LinkDataAlias, string Subject, string Description) { }
        public virtual void DeleteGroupData(string SiteId, string GroupDataId) { }
        public virtual void SaveXml(
            IDbTransaction Trans,
            string SiteId,
            string AssetCode,
            string GroupDataId,
            DateTime EntryDate,
            string DataId) { }

        public virtual string AddCmsData(
                IDbTransaction Trans,
                string SiteId,
                string WorkflowDefId,
                string DataLanguage,
                string DataId,
                CmsDataCls OCmsData,
                bool blnSaveXml
            ) { return null; }

        public virtual string AddCmsData(
              IDbTransaction Trans,
              string SiteId,
              string WorkflowDefId,
              string DataLanguage,
              string DataId,
              CmsDataCls OCmsData,
              CmsVoteAnswerItemCls[] CmsVoteAnswerItems,
              bool blnSaveXml) { return null; }

        public virtual void SaveCmsData(
                IDbTransaction Trans,
                string SiteId,
                string DataId,
                CmsDataCls OCmsData,
                bool blnSaveXml) { }

        public virtual void SaveCmsData(
               IDbTransaction Trans,
               string SiteId,
               string DataId,
               CmsDataCls OCmsData,
               CmsVoteAnswerItemCls[] CmsVoteAnswerItems,
               bool blnSaveXml
           ) { }

        //public virtual void SaveCmsData(string SiteId, string DataId, string GroupDataId, CmsDataCls OCmsData) { }
        public virtual void DeleteCmsData(string SiteId, string DataId) { }
        public virtual void ChangeAvatarFile(string SiteId, string DataId, string AvatarFile) { }
        public virtual void ChangeAttachDocFile(string SiteId, string DataId, string AttachDocFile) { }
        public virtual void PublicData(IDbTransaction Trans, string SiteId, string DataId) { }
        public virtual void UnPublicData(IDbTransaction Trans, string SiteId, string DataId) { }
        public virtual void PublicGroupData(string SiteId, string GroupDataId) { }
        public virtual void UnPublicGroupData(string SiteId, string GroupDataId) { }
        public virtual CmsDataCls[] ReadingCmsData(string SiteId, string GroupDataId, string ParentDataId) { return null; }
        public virtual CmsDataCls[] ReadingCmsDataForDataType(string SiteId, string DataType) { return null; }
        public virtual CmsDataCls[] ReadingCmsDataForVote(string SiteId, string GroupDataId, string ParentDataId) { return null; }
        public virtual GroupDataCls[] ReadingGroupDataForSurvey(string SiteId, string AssetCode) { return null; }
        public virtual CmsDataCls[] ReadingCmsDataForVoteDetail(
            string SiteId,
            string GroupDataId,
            string ParentDataId,
            string UserId) { return null; }

        public virtual CmsDataCls[] ReadingCmsDataIsPublic(string SiteId, string GroupDataId, string ParentDataId) { return null; }
        public virtual CmsDataCls[] ReadingCmsDataIsPublicByUser(string SiteId, string GroupDataId, string ParentDataId, string EntryName, string isPublic, string sortIndex, string releasefrom,
            string docfield,
            string doctype,
            string docsigner,
            string docNo) { return null; }
        public virtual CmsDataCls[] SearchAdvancePublicCmsData(string SiteId, string GroupDataId, string ParentDataId, string EntryName, string isPublic, string sortIndex,
            string documentno,
             string Subject,
             string sfd,
             string std,
             string rfd,
             string rtd,
             string efd,
             string etd,
             string releasefrom,
             string docfield,
             string doctype,
             string docsigner,
             string gdf, 
            string status,
            string yrf,
            string yrt
            ) { return null; }

        public virtual CmsDataCls[] SearchAdvancePublicCmsData(string SiteId, string GroupDataId, string ParentDataId, string EntryName, string isPublic, string sortIndex,
           string documentno,
            string Subject,
            string sfd,
            string std,
            string rfd,
            string rtd,
            string efd,
            string etd,
            string releasefrom,
            string docfield,
            string doctype,
            string docsigner
           ) { return null; }

        public virtual CmsDataCls[] ReadingTopCmsDataIsPublicSortByDate(string SiteId, string GroupDataId, string ParentDataId, string SortType, int Top) { return null; }
        public virtual CmsDataCls[] ReadingCmsDataIsPublicSortByDate(string SiteId, string GroupDataId, string ParentDataId, string SortType) { return null; }
        public virtual CmsDataCls[] ReadingCmsDataIsPublicExclusive(string SiteId, string GroupDataId, string ExclusideId, int TOP) { return null; }
        public virtual GroupDataCls[] ReadingGroupDataForInput(string SiteId, string DataType) { return null; }
        public virtual GroupDataCls[] ReadingGroupDataForInput(string SiteId) { return null; }
        public virtual CmsDataCls[] SearchCmsData(string SiteId, string DataTypeId, string Subject, string Description) { return null; }
        public virtual CmsDataCls[] SearchCmsData(string SiteId, string DataTypeId, string Keyword) { return null; }
        public virtual void SendContactUs(
            string SiteId,
            string FromName,
            string FromEmail,
            string FromAddress,
            string FromPhone,
            string FromTitle,
            string SendContent) { }
        public virtual GroupDataCls[] ReadingGroupDataForVote(string SiteId, string DataTypeId, string AssetCode, string StudentId) { return null; }
        public virtual void AddDocumentRelation(string SiteId, string SrcDataId, string RelDataId, string RelationTypeId) { }
        public virtual void AddDocumentRelationList(string SiteId, string SrcDataId, string[] RelDataId) { }
        public virtual void DeleteDocumentRelation(string SiteId, string RelationDataId) { }
        public virtual void DeleteDocument(string SiteId, string DataId) { }
        public virtual CmsDataRelationCls[] ReadingDocumentRelation(string SiteId, string SrcDataId, string RelationTypeId) { return null; }
        public virtual CmsDataRelationCls[] ReadingDocumentRelationOut(string SiteId, string SrcDataId, string RelationTypeId) { return null; }
        public virtual Collection<CmsDataCls> GetDocumentRelation(string SiteId, string DataId, Collection<CmsDataCls> ResCmsData) { return null; }
        public virtual Collection<CmsDataCls> GetDocumentRelationRevert(string SiteId, string DataId, Collection<CmsDataCls> ResCmsData) { return null; }
        public virtual void SendForPublish(string SiteId, string DocumentId) { }
        public virtual CmsDataCls[] ReadingCmsDataForPublish(string SiteId, string GroupDataId) { return null; }

        //sync
        public virtual void SyncGroupDataCategory(string SiteId, Collection<GroupDataCategoryCls> GroupDataCategories) { }
        public virtual GroupDataCategoryCls[] ReadingGroupDataCategory(string SiteId, string DataLanguageId){return null;}
        public virtual GroupDataCategoryCls[] ReadingGroupDataCategoryForWorkflowAction(
            string SiteId, string DataLanguageId, string RoleId, string UserId) { return null; }

        public IndexServiceInfo GetXmlIndexServiceInfo(string SiteId)
        {
            IndexServiceInfo OIndexServiceInfo = new IndexServiceInfo();
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            OIndexServiceInfo.IndexPath = WebConfig.GetConfigFromXml(OSiteParam, "IndexPath");
            OIndexServiceInfo.whatToIndex = WebConfig.GetConfigFromXml(OSiteParam, "whatToIndex");

            return OIndexServiceInfo;
        }

        public IndexServiceInfo GetDocumentIndexServiceInfo(string SiteId)
        {
            IndexServiceInfo OIndexServiceInfo = new IndexServiceInfo();
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            OIndexServiceInfo.IndexPath = WebConfig.GetConfigFromXml(OSiteParam, "IndexPathDocument");
            OIndexServiceInfo.whatToIndex = WebConfig.GetConfigFromXml(OSiteParam, "whatToIndexDocument");

            return OIndexServiceInfo;
        }


        public string ProcessDate(int SDate)
        {
            string MS = "";
            if (SDate == 1) MS = "January";
            if (SDate == 2) MS = "February";
            if (SDate == 3) MS = "March";
            if (SDate == 4) MS = "April";
            if (SDate == 5) MS = "May";
            if (SDate == 6) MS = "June";
            if (SDate == 7) MS = "July";
            if (SDate == 8) MS = "August";
            if (SDate == 9) MS = "September";
            if (SDate == 10) MS = "October";
            if (SDate == 11) MS = "November";
            if (SDate == 12) MS = "December";
            return MS;
        }

        public string GetSaveDir(string SiteId, DateTime CurrentTime, string AssetCode,string GroupDataId)
        {
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            string SavePath = WebConfig.DataPathRoot(OSiteParam) + "\\DocumentArchives";
            System.IO.Directory.CreateDirectory(SavePath);
            SavePath = SavePath + "\\" + AssetCode;
            System.IO.Directory.CreateDirectory(SavePath);

            SavePath = SavePath + "\\Xml";
            SavePath = SavePath + "\\Archive";
            
            System.IO.Directory.CreateDirectory(SavePath);
            SavePath = SavePath + "\\" + CurrentTime.Month.ToString().PadLeft(2, '0') + CurrentTime.Year;
            System.IO.Directory.CreateDirectory(SavePath);
            return SavePath;
        }

        public virtual DataSaveHistoryCls[] ReadingDataSaveHistory(string SiteId, string CmsDataId) { return null; }
        public virtual DataSaveHistoryCls[] ReadingDataSaveHistoryDetail(string SiteId,string DataSaveHistoryId, string CmsDataId) { return null; }
        public virtual void ExecuteIndexService(string SiteId){}

        public virtual StudentSurveyCls[] ReadingVotedStudentList(string SiteId, string GroupDataId) { return null; }
        public virtual StudentSurveyCls CreateStudentSurveyModel(string SiteId, string StudentSurveyId) { return null; }
        public virtual GroupDataFolderCls CreateGroupDataFolderModel(IDbTransaction Trans, string SiteId, string GroupDataFolderId) { return null; }
        public virtual GroupDataFolderCls[] ReadingGroupDataFolder(IDbTransaction Trans, string SiteId, string GroupDataId, string ParentGroupDataFolderId) { return null; }
        public virtual string AddGroupDataFolder(IDbTransaction Trans, string SiteId, string GroupDataId, string ParentGroupDataFolderId, string FolderName, int SortIndex) { return null; }
        public virtual string SaveGroupDataFolder(IDbTransaction Trans, string SiteId, string GroupDataId, string GroupDataFolderId, string FolderName, int SortIndex) { return null; }
        public virtual void DeleteGroupDataFolder(IDbTransaction Trans, string SiteId, string GroupDataId, string GroupDataFolderId) { }
        public virtual void MoveGroupDataFolder(IDbTransaction Trans, string SiteId, string GroupDataId, string MoveGroupDataFolderId, string ToGroupDataFolderId){}
        public virtual void MoveDocumentToGroupDataFolder(IDbTransaction Trans, string SiteId, string GroupDataId, string MoveDocumentId, string ToGroupDataFolderId){}        
        public virtual  CmsDataCls ReadingCmsDataForVoteDetailText(
            string SiteId,
            string GroupDataId,
            string ParentDataId,
            string StudentSurveyId){return null;}
    }
}
